package com.xiyu.service.controller.admin.unit;
import com.xiyu.service.vo.unit.unit.UnitGetGroupCategoryInfoOutput;
import com.xiyu.service.vo.unit.unit.UnitSimpleListOutput;
import com.xiyu.service.vo.unit.unit.UnitSingleGetOutput;
import com.xiyu.service.vo.unit.unit.UnitUpdateInput;
import com.xiyu.service.vo.unit.unit.UnitCreateInput;
import com.xiyu.service.vo.unit.unit.UnitPageQueryOutput;
import com.xiyu.service.vo.unit.unit.UnitPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.unit.UnitService;

@Tag(name = "单位管理")
@RestController
@RequestMapping("/unit/unit")
@Validated
public class UnitController {

    @Resource
    private UnitService unitService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询单位")
    public CommonResult<PageResult<UnitPageQueryOutput>> pageQuery(@Valid UnitPageQueryInput inputVO) {
        return success(unitService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增单位")
    @PreAuthorize("@ss.hasPermission('unit:unit:create')")
    public CommonResult<Boolean> create(@Valid @RequestBody UnitCreateInput inputVO) {
        return success(unitService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新单位")
    @PreAuthorize("@ss.hasPermission('unit:unit:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody UnitUpdateInput inputVO) {
        return success(unitService.update(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个单位")
    @Parameter(name = "id", description = "办公单位主键ID", example = "")
    public CommonResult<UnitSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(unitService.singleGet(id));
    }

    @GetMapping("/simple-list")
    @Operation(summary = "查询单位")
    public CommonResult<List<UnitSimpleListOutput>> simpleList() {
        return success(unitService.simpleList());
    }

    @GetMapping("/get-group-category-info")
    @Operation(summary = "获取按单位类别聚合信息")
    public CommonResult<List<UnitGetGroupCategoryInfoOutput>> getGroupCategoryInfo() {
        return success(unitService.getGroupCategoryInfo());
    }

}
